package com.edie.customview.modular.mymvp;

import android.util.Log;

import com.edie.customview.basemvp.BasePresenter;

import java.lang.ref.WeakReference;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * edie create on 2018/7/19
 */
public class MyMvpPresenterImpl extends BasePresenter<MyMvpContract.IMyMvpView> implements MyMvpContract.IMyMvpPresenter {
    private static final String TAG = MyMvpPresenterImpl.class.getSimpleName();
    private MyMvpContract.IMyMvpModel mMyMvpModel;

    public MyMvpPresenterImpl(MyMvpContract.IMyMvpView view) {
        super(view);
        mMyMvpModel = new MyMvpModelImpl();
    }

    @Override
    public void loadMsg(String msgId) {
        mMyMvpModel.loadMsg(msgId)
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        if (isAttach()) {
                            getView().showMsg(s);
                        } else {
                            Log.i(TAG, "onNext: " + s);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
